/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.yunhoo.asset.bean;

import com.yunhoo.base.model.Department;
import com.yunhoo.base.model.Person;
import com.yunhoo.sys.db.util.IbatisTemplate;
import com.yunhoo.sys.util.common.CommonParam;
import com.yunhoo.sys.util.common.LoginParam;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;


@ManagedBean(name = "deptAndEmp")
@SessionScoped
public class DeptAndEmpHelpBean {

    private final String NAMESPACE = "";
    private Department dept = new Department();
    private Person user = new Person();
    private List<Department> deptList = new ArrayList();
    private List<SelectItem> selectItemList;
    private List person = new ArrayList();
    private List psnForCancel = new ArrayList();//取消审核单据的人员列表
    private String deptCode = "";
    private String deptCode1 = "";

    public DeptAndEmpHelpBean() {
        intiDepartmentInfo();
    }

    public void deptChange() {
        person = new ArrayList();
        if (deptCode != null) {
            Person param = new Person();
            param.setOrgCode(LoginParam.getOrg().getCode());
            param.setIyear(LoginParam.getIyear());
            param.setDeptCode(deptCode);
            List<Person> personlist = IbatisTemplate.queryForList("person.queryListByDept", param);
            if (personlist != null && personlist.size() > 0) {
                for (Person p : personlist) {
                    person.add(new SelectItem(p.getCpsn_number(), p.getCpsn_name()));
                }
            }
        }
    }

    public void deptChange1(ValueChangeEvent event) {
        String code = (String) event.getNewValue();
        person = new ArrayList();
        if (code != null) {
            Person param = new Person();
            param.setOrgCode(LoginParam.getOrg().getCode());
            param.setIyear(LoginParam.getIyear());
            param.setDeptCode(code);
            List<Person> personlist = IbatisTemplate.queryForList("person.queryListByDept", param);
            if (personlist != null && personlist.size() > 0) {
                for (Person p : personlist) {
                    person.add(new SelectItem(p.getCpsn_number(), p.getCpsn_name()));
                }
            }
        }
    }

    public void deptForCancelChange() {
        String deptcode = deptCode1;
        Person param = new Person();
        param.setOrgCode(LoginParam.getOrg().getCode());
        param.setIyear(LoginParam.getIyear());
        param.setDeptCode(deptcode);
        List<Person> personlist = IbatisTemplate.queryForList("person.queryListByDept", param);
        psnForCancel = new ArrayList();
        if (personlist != null && personlist.size() > 0) {
            for (Person p : personlist) {
                psnForCancel.add(new SelectItem(p.getCpsn_number(), p.getCpsn_name()));
            }
        }
    }

    public void buildPsnList(String str) {
    }

    public void personChange(ValueChangeEvent event) {
        String cpsn_number = (String) event.getNewValue();
        user.setCpsn_number(cpsn_number.trim());
        //user.setCpsn_name(pers.get(cpsn_number.trim()));
    }

    private void intiDepartmentInfo() {
        selectItemList = new ArrayList();
        deptList = CommonParam.departmentList();
        for (Department d : deptList) {
            selectItemList.add(new SelectItem(d.getCode(), d.getName()));
        }
    }

    public Department getDept() {
        return dept;
    }

    public void setDept(Department dept) {
        this.dept = dept;
    }

    public List<Department> getDeptList() {
        return deptList;
    }

    public void setDeptList(List<Department> deptList) {
        this.deptList = deptList;
    }

    public List getPerson() {
        return person;
    }

    public void setPerson(List person) {
        this.person = person;
    }

    public List<SelectItem> getSelectItemList() {
        return selectItemList;
    }

    public void setSelectItemList(List<SelectItem> selectItemList) {
        this.selectItemList = selectItemList;
    }

    public Person getUser() {
        return user;
    }

    public void setUser(Person user) {
        this.user = user;
    }

    public List getPsnForCancel() {
        return psnForCancel;
    }

    public void setPsnForCancel(List psnForCancel) {
        this.psnForCancel = psnForCancel;
    }

    public String getDeptCode() {
        return deptCode;
    }

    public void setDeptCode(String deptCode) {
        this.deptCode = deptCode;
    }

    public String getDeptCode1() {
        return deptCode1;
    }

    public void setDeptCode1(String deptCode1) {
        this.deptCode1 = deptCode1;
    }
}
